
/**
** \file       exec_cmdline.h
**
** \brief      This file contains functions declaration about execution of
**             arguments given to the 42sh.
**
** \authors    Ben M'rad Hanna, Boillot Ulysse, De Oliveira
**             Guillaume, Laterem Hamza, Nguyen Viet Dung
**
**
** \version    0.9
**
** \date       27 November 2010
**
*/

#ifndef EXEC_CMDLINE_H_
# define EXEC_CMDLINE_H_

# define SIZE2 14

# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>

# include "options_parser.h"
# include "readline/read_my_line.h"
# include "lexer/token.h"
# include "parser/rules.h"
# include "parser/ast_printer.h"
# include "execution/execution.h"
# include "parser/ast.h"

/**
** \struct     s_data
**
** \brief      s_data is the type of our global variable. It contains our
**             current lexer, our current ast, and the tab of understood token
**
*/

typedef struct  data
{
    s_lexer     *lexer;
    s_token     *tab_token;
    s_ast       *ast;
    char        **tab_keyword;
    char        **envp;
}               s_data;

extern s_data   *g_data;

/**
** \fn         init_data
**
** \brief      init_data initializes the global struct g_data
**
** \param      void
**
** \return     init_data returns g_data filled correctly
**
*/

s_data          *init_data(char         **envp);

/**
** \fn         int             exec_file(char          *file)
** \brief      exec_file will execute the code in the file given
**             as argument.
**
** \param      file is a string: the path from the directory of the binary
**             42sh create by our makefile.
**
** \return     exec_file returns 0 if the file exists and if its content can
**             be executed by our programm. Else, it returns 1;
**
*/

int             exec_file(char          *file,
                          s_cmd         *cmd,
                          char          **envp);

/**
** \fn         int             exec_str(char           *str)
** \brief      exec_str will execute the string given as argument.
**
** \param      str is the string which has to be executed.
**
** \return     exec_str returns 0 if the string can be executed by our
**             programm. Else, it returns 1.
**
*/

int             exec_str(char           *str,
                         s_cmd          *cmd,
                         char           **envp);

/**
** \fn         int     exec_cmdline(s_cmd      *cmd_res, char       **argv);
** \brief      exec_cmdline execute the main command line (options, file...)
**
** \param      cmd_res is the result of the parsing of the command line done
**             sooner. This struct contains all options and files given.
**             argv is the array of argument given to the main function.
**
** \return     it returns 1 if exec_file or exec_str failed. Else,
**             it returns 0.
**
*/

int             exec_cmdline(s_cmd      *cmd_res,
                             char       **argv,
                             char       **envp);

#endif /* !EXEC_CMDLINE_H_ */
